from app import db
from datetime import datetime


class LoggerInfoBlack(db.Model):
    __tablename__ = 'logger_info_black'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    type = db.Column(db.String(100), nullable=True)
    info = db.Column(db.String(1000), nullable=True)
    ip = db.Column(db.String(100), nullable=True)
    url = db.Column(db.String(1000), nullable=True)
    remark = db.Column(db.String(255), nullable=True)
    create_time = db.Column(db.DateTime, default=datetime.utcnow)


    __table_args__ = (
        db.Index('idx-ip', 'ip'),
        db.Index('idx-txt', 'remark'),
        db.Index('idx-type', 'type'),
    )

    def to_json(self):
        return {
            'id': self.id,
            'type': self.type,
            'info': self.info,
            'remark': self.info,
            'ip': self.ip,
            'url': self.url,
            'create_time': self.create_time.isoformat(),
        }
